package com.jerry.base.java8.lambda;

import java.util.stream.Stream;

/**
 * 对象::非静态方法的方法引用
 *
 * @author Jerry
 * @since 2024/7/24 20:12
 */
public class MethodRef3 {

    public static void main(String[] args) {
        Util util = new Util();
        Stream.of(
                        new Student("张无忌", "男"),
                        new Student("周芷若", "女"),
                        new Student("宋青书", "男")
                )
                .filter(util::isMale)
                .map(util::getName)
                .forEach(System.out::println);
    }

    record Student(String name, String sex) {

        boolean isMale() {
            return sex.equals("男");
        }

        void print() {
            System.out.println(this);
        }
    }

    static class Util {

        boolean isMale(Student s) {
            return s.isMale();
        }

        String getName(Student s) {
            return s.name();
        }
    }
}